﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Common;
using System.Configuration;

namespace Catering.UserTraining
{
    public partial class upfile : System.Web.UI.Page
    {
        public int i_MaxSize = 1024 * 1024 * 100;     //文档上传的大小限制
        public string s_UpPath = "TempImg/";    //文档上传的地址
        public string s_FileNamePrefix = "";    //要生成的文档的名称前缀
        public int i_AttachSave = 1;            //文档保存的方式1：年月日，2：年月
        public string s_FileTye = "*.doc;*.docx;*.ppt;*.pptx;*.xls;*.xlsx";           //文档类型
        public string s_ResultControl_Show = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            string sUpPath = CommRequest.GetString("UpPath");
            string sFileTye = CommRequest.GetString("FileTye");
            i_MaxSize = 1024 * 1024 * Convert.ToInt32(ConfigurationManager.AppSettings["MaxSize"].ToString());
            i_MaxSize = CommRequest.GetInt("MaxSize", i_MaxSize);
            s_FileNamePrefix = CommRequest.GetString("FileNamePrefix");
            s_UpPath = string.IsNullOrEmpty(sUpPath) ? s_UpPath : sUpPath;
            s_FileTye = string.IsNullOrEmpty(sFileTye) ? s_FileTye : ("*." + sFileTye.Replace("|", ";*."));
            s_ResultControl_Show = CommRequest.GetString("ResultControl_Show");
            i_AttachSave = CommRequest.GetInt("AttachSave", 1);

            string action = CommRequest.GetString("action");

            if (action == "ok")
            {
                string sPath = ConfigurationManager.AppSettings["FileRoot"] + s_UpPath;
                string sError = "";
                string sSuccess = "";
                string sFileName = "";
                string sSaveDir = "";
                string sFileSize = "";
                WorkTool.SaveRequestFiles(s_FileNamePrefix, i_MaxSize, "file1", sPath, i_AttachSave, true, out sFileSize, out sError, out sSuccess, out sFileName, out sSaveDir);
                Response.Write("{\"ErrorStr\":\"" + sError + "\",\"SuccessStr\":\"" + sSuccess + "\",\"FileSize\":\"" + sFileSize + "\",\"FileName\":\"" + sSaveDir.Replace("\\", "/") + sFileName + "\"}");
                Response.End();
            }
        }
    }
}